package com.ccb.lms.dao;

import java.sql.SQLException;
import java.util.List;

import com.ccb.lms.model.Borrow;
import com.ccb.lms.util.BasePage;
import com.ibatis.sqlmap.client.SqlMapClient;

public class BorrowDAO implements IBorrowDAO {
	private SqlMapClient sqlMapClient = null;

	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

	public boolean insertBorrow(Borrow borrow) throws SQLException {
		sqlMapClient.insert("borrow.insertBorrow", borrow);
		return true;
	}

	public boolean deleteBorrow(Integer borrowNO) throws SQLException {
		sqlMapClient.delete("borrow.deleteBorrow", borrowNO);
		return true;
	}

	public boolean updateBorrow(Borrow borrow) throws SQLException {
		sqlMapClient.update("borrow.updateBorrow", borrow);
		return true;
	}

	@SuppressWarnings("unchecked")
	public List<Borrow> getAllBorrows() throws SQLException {
		
		return sqlMapClient.queryForList("borrow.getAllBorrows");
	}

	public Borrow getBorrowByNO(Integer borrowNO) throws SQLException {
		
		return (Borrow) sqlMapClient.queryForObject("borrow.getBorrowByNO", borrowNO);
	}

	public int getBorrowCount() throws SQLException {
		
		return (Integer) sqlMapClient.queryForObject("borrow.recordCount");
	}

	public BasePage getBasePage(int currentPage, int showRecordNum)
			throws SQLException {
		
		return new BasePage(currentPage, getBorrowCount(), showRecordNum);
	}

	@SuppressWarnings("unchecked")
	public List<Borrow> getBorrowByPage(BasePage basePage) throws SQLException {
		
		return sqlMapClient.queryForList("borrow.getBorrowByPage", basePage);
	}
}
